﻿using System;
using System.Data.Linq;
using System.Windows.Forms;
using Sunlight.Dispatch.Dal;
using Sunlight.Dispatch.Tools;

namespace Sunlight.Dispatch.UI {
    public partial class MainFrm : Form {
        public MainFrm() {
            InitializeComponent();
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e) {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e) {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e) {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e) {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e) {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e) {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e) {
            foreach(Form childForm in MdiChildren) {
                childForm.Close();
            }
        }

        private void tsmiBusinessConfig_Click(object sender, EventArgs e) {
            var frm = new BusinessSearchFrm();
            frm.MdiParent = this;
            frm.Show();
        }

        private void ToolStripInterfaceMenuItem_Click(object sender, EventArgs e) {
            var frm = new LogInformationFrm();
            frm.MdiParent = this;
            frm.Show();
        }

        private void ToolStripInterfaceBasicInfoMenuItem_Click(object sender, EventArgs e) {
            var frm = new TinfManagementFrm();
            frm.MdiParent = this;
            frm.Show();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
            var frm = new AboutBox();
            frm.MdiParent = this;
            frm.Show();
        }

        private void ToolStripFileMenuItem_Click(object sender, EventArgs e) {
            var fileLogFrm = new FileLogInformationFrm();
            fileLogFrm.MdiParent = this;
            fileLogFrm.Show();
        }

        private void tsmiDispatchConfig_Click(object sender, EventArgs e) {
            var frm = new SideListConfigFrm();
            frm.MdiParent = this;
            frm.EditSubmitted += this.Frm_EditSubmitted;
            frm.Show();
        }

        //用此事件弹出调度方维护界面
        private void Frm_EditSubmitted(object sender, Extensions.SubmittedEventArgs e) {

        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e) {
            var frm = new TSideOperationFrm();
            frm.MdiParent = this;
            frm.EditSubmitted += Frm_EditSubmitted1;
            frm.Show();
        }

        private void Frm_EditSubmitted1(object sender, Extensions.SubmittedEventArgs e) {
            var form = sender as Form;
            if(form == null)
                return;
            form.Close();
        }

        private void otsmiSetting_Click(object sender, EventArgs e) {
            var initFrm = new InitFrm();
            initFrm.MdiParent = this;
            initFrm.Show();
        }

        private void toolStripButton2_Click(object sender, EventArgs e) {
            var frm = new TinfManagementFrm();
            frm.MdiParent = this;
            frm.Show();
        }

        private void tsbConfig_Click(object sender, EventArgs e) {
            var setting = new InterfaceSettingFrm();
            setting.MdiParent = this;
            //添加接口配置，默认字段赋值
            var intf = setting.CreateObjectToEdit<TIntf>(string.Empty);
            intf.Class = 0;
            intf.DataClass = 0;
            intf.CompleteMethod = string.Empty;
            intf.Sequential = false;
            intf.TRule = new EntitySet<TRule>();
            intf.Status = (int)RunStatus.启动;
            setting.Show();
        }
    }
}
